<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>订单页面</title>

		<link rel="stylesheet" href="css/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="css/style.css">
		<script src="js/app.js" charset="UTF-8"></script>
		<script src="js/vue.js"></script>
		<script src="js/axios.min.js"></script>
		<script src="js/vue-cookies.js"></script>
		<script src="css/layui/layui.js" charset="utf-8"></script>
		<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
	</head>
	<body>
		<div id="app">
			<ul class="layui-nav" style="z-index:999">
				<li class="layui-nav-item">
					<a href="index.html">主页</a>
				</li>
			
			<li  v-show="!loginflag" class="layui-nav-item" style="margin-left: 400px;">
				<a href="javascript:void(0);" @click="loginplease">{{userShowName}}</a>
			</li>
				<li  v-show="loginflag" class="layui-nav-item" style="margin-left: 400px;">
					<a href="javascript:void(0);" @click="loginplease">{{userShowName}}</a>
					<dl class="layui-nav-child">
						<dd> <a href="user.html">个人中心</a></dd>
						<dd><a href="javascript:void(0);" onclick="clearAllCookie()">注销</a></dd>
					</dl>
				</li>
				<li v-show="loginflag" class="layui-nav-item">
					<a href="order.html">我的订单</a>
					<dl class="layui-nav-child">
						<dd><a href="HistoryOrder.html">历史订单</a></dd>
					</dl>
				</li>
				<li v-show="loginflag" class="layui-nav-item">
					<a href="shoppingcart.html">购物车<span class="layui-badge">{{shoppingcartnumber}}</span></a>
				</li>
				<li v-show="$cookies.get('userType')==1" class="layui-nav-item">
					<a href="myShop.html">创建商品</a>
					<dl class="layui-nav-child">
						<dd><a href="myShopOrder.html">商家订单</a></dd>
					</dl>
				</li>
			</ul>









<div style="z-index: 0;">
  <table class="layui-hide" id="test" lay-filter="test"></table>

</div>
  </div>

   
  <script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
      <button class="layui-btn layui-btn-sm" lay-event="getCheckData">一键发货</button>
    </div>
  </script>
   
		<script type="text/javascript">
			var vm = new Vue({
				el: '#app',
				data: {
					userShowName: '请登录',
					username: '',
					loginflag: false,
					shopOrderList: [],
					page: 1,
					haveInit: false,
					shoppingcartnumber: 0
				},
				filters: {
					keepTwoNum: function(value) {
						value = Number(value)
						return value.toFixed(2)
					},
					statusFilter(value) {
						value = Number(value)
						if (value == 0) {
							return "待发货"
						}
						if (value == 1)
							return "待收货"
					}
				},
				methods: {
		
					loginplease: function() {
						if (this.loginflag)
							window.location.href = 'user.html'; //跳转主页
						else
							window.location.href = 'login.html'; //跳转主页
					},
					},
					
				created: function() {
					checklogin().then(x => {
						if (x) {

							if ($cookies.get("userName") != null)
								this.username = $cookies.get("userName")
							if ($cookies.get("userShowName") != null)
								this.userShowName = $cookies.get("userShowName")
							this.loginflag = $cookies.get("loginflag")

						} else {
						layui.use('layer', function(){
							  var layer = layui.layer;
							  layer.open({
								title:"提示"//不显示标题栏
							    ,closeBtn: false
							    ,shade: 0.8
							    ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
							    ,btn: ['确认', '取消']
							    ,btnAlign: 'c'
							    ,moveType: 1//拖拽模式，0或者1
								,type:0
							    ,content: '请重新登陆再使用店铺功能'
							    ,yes: function(index, layero){
							     	window.location.href = 'login.html'
								   layer.close(index);
							      },
								  btn2: function(index, layero){
									  	window.location.href = 'index.html'
							  }
							  });
							});    
						}
					})

				},
				mounted: function() {


				}


			})
		</script>


<script>
layui.use('table', function(){
  var table = layui.table;
  
  var tableIns=table.render({
    elem: '#test'
  ,url: URL+'/shop/shopOrderSelect' //数据接口
  ,page: true//开启分页
  ,method:'post'
  ,where:{
  	userId:$cookies.get("userId"),
  	userName:$cookies.get("userName"),
      passWord:$cookies.get("passWord")
  	
  }
    ,parseData: function(res){ //res 即为原始返回的数据
	console.log(res.result)
      return {
        "code": res.code, //解析接口状态
        "msg": res.msg, //解析提示文本
        "count": res.count, //解析数据长度
        "data": res.result ,//解析数据列表
      };
    }
  ,request: {
      pageName: "Page" //页码的参数名称，默认：page
    }
    ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
    ,title: '商家发货表'
    ,cols: [[
      {type: 'numbers',fixed: 'left',title:"序号"}
	  ,{field:'status', title:'订单状态', width:120, sort: true,templet: function(res){
	    if(res.status==0)
	  		return "等待商家发货"
	  		else
	  		return "等待用户收货"
	  }}
      ,{field:'orderId', title:'订单编号', width:120,  sort: true}
      ,{field:'userName', title:'用户账号', width:120}
      ,{field:'userShowName', title:'用户昵称', width:150}
      ,{field:'userAddress', title:'用户地址'}
      ,{field:'date', title:'日期',width:200,sort: true}
	   ,{field:'itemId', title:'商品编号', width:90}
	       ,{field:'itemName', title:'商品名'}
	    ,{field:'number', title:'购买数量', width:130}
  
  ,{field:'price', title:'商品总价', width:130,templet:function(res){
	  return "¥"+res.price.toFixed(2)
  }}
	  
    ]]
    ,page: true
  });
  
  //头工具栏事件
  table.on('toolbar(test)', function(obj){
    switch(obj.event){
      case 'getCheckData':
	  console.log("一键发货")
	  layer.confirm('是否发货', {title:'提示'}, function(index){
		  let param = new URLSearchParams()
		  	       param.append('userId', $cookies.get("userId"))
		  	       param.append('passWord', $cookies.get("passWord"))
		  	       param.append('userName', $cookies.get("userName"))
		  	       console.log(param.toString())
		  	       axios.post(URL + '/shop/fahuo',param
		  )
		  	       	.then(function(response) {
		  	       		if (response.data.code == 1) {
		  	       			layui.use('layer', function(){
		  	       				layer.msg("成功发货"+response.data.count+"件订单",{time:1500})
		  	       			});
							tableIns.reload({
							});
		  	       		} else if (response.data.code == 0) {
		  					layui.use('layer', function(){
		  					  var layer = layui.layer;
		  					 layer.msg('发货，请检查登陆状态')
		  					}); 
		  	       			console.log(response)
		  	       			console.log(response.data.msg)
		  	       
		  	       		}
		  	       	})
		  	       	.catch(function(error) {
		  	       		console.log(error);
		  	       	});
	    layer.close(index);
	  });
      break;
    };
  });
  
});
		<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
			layui.use('element', function() {
				var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块

				//监听导航点击
				element.on('nav(demo)', function(elem) {
					//console.log(elem)
					layer.msg(elem.text());
				});
			});
		</script>

	</body>
</html>
